/**
 * TinyMCE customizations for ExtJS
 *
 * @author Max Romanovsky
 */

Ext.ns('Ext.ux.Bike.tinymce');
// Settings for Ext.ux.TinyMCE
Ext.ux.Bike.tinymce.settings = {
	gecko_spellcheck : true,
	mode : 'none',
	skin : 'o2k7',
	skin_variant : 'silver',
	strict_loading_mode : true,
	theme : 'advanced',
	theme_advanced_blockformats : 'p,address,pre,h1,h2,h3,h4,h5,h6,blockquote,code',
	theme_advanced_buttons1 : 'preview,|,selectall,cut,copy,paste,pastetext,pasteword,|,jaretypograph,phptypography,removeformat,|,undo,redo,|,link,unlink,anchor,|,search,replace,|,image,media,|,visualaid,visualchars,code,|,fullscreen,|,help',
	theme_advanced_buttons2 : 'formatselect,styleselect,|,bold,italic,underline,strikethrough,|,sub,sup,|,bullist,numlist,|,charmap,hr,nonbreaking,|,blockquote,cite,abbr,acronym',
	theme_advanced_buttons3 : 'fontselect,fontsizeselect,|,justifyleft,justifycenter,justifyright,justifyfull,|,forecolor,backcolor,|,outdent,indent',
	theme_advanced_buttons4 : 'tablecontrols',
	theme_advanced_statusbar_location : 'bottom',
	theme_advanced_toolbar_align : 'left',
	theme_advanced_toolbar_location : 'top',
	// doctype : '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	// "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
	entity_encoding : 'raw',
	fix_list_elements : true,
	fix_table_elements : true,
	convert_urls : false,
	// content_css : '/style/content.css',
	plugins : 'advimage,advlist,contextmenu,fullscreen,jaretypograph,inlinepopups,media,nonbreaking,paste,phptypography,preview,print,safari,searchreplace,table,visualchars,xhtmlxtras',
	table_default_cellspacing : 0,
	table_default_border : 1,
	paste_strip_class_attributes : 'mso',

	// fileBrowser-related
	folderRoot : '/uploads/',
	actionURL : '/Bike/controllers/filebrowser.php',
	titleFileBrowser : 'File Browser',
	titleImageBrowser : 'Image Browser',
	file_browser_callback : function(field_name, url, type, win) {
		this.fieldName = field_name;
		this.win = win;
		this.imageBrowser = (type == 'image');

		if (this.imageBrowser) {
			if (!this.fbImg) {
				this.fbImg = new Ext.ux.fileBrowser({
					folderRoot : Ext.ux.Bike.tinymce.settings.folderRoot,
					actionURL : Ext.ux.Bike.tinymce.settings.actionURL,
					modal : true,
					imageBrowser : true,
					handler : function(filename) {
						this.win.document.getElementById(this.fieldName).value = filename;
						if (Ext.isDefined(this.win.ImageDialog)) {
							this.win.ImageDialog.showPreviewImage(filename);
						}
						this.fb.hide();
						this.wg.unregister(this.fb);
					}.createDelegate(this),
					statusBar : true,
					title : Ext.ux.Bike.tinymce.settings.titleImageBrowser
				});
			}
			this.fb = this.fbImg;
		} else {
			if (!this.fbFb) {
				this.fbFb = new Ext.ux.fileBrowser({
					folderRoot : Ext.ux.Bike.tinymce.settings.folderRoot,
					actionURL : Ext.ux.Bike.tinymce.settings.actionURL,
					modal : true,
					imageBrowser : false,
					handler : function(filename) {
						this.win.document.getElementById(this.fieldName).value = filename;
						if (Ext.isDefined(this.win.ImageDialog)) {
							this.win.ImageDialog.showPreviewImage(filename);
						}
						this.fb.hide();
						this.wg.unregister(this.fb);
					}.createDelegate(this),
					statusBar : true,
					title : Ext.ux.Bike.tinymce.settings.titleFileBrowser
				});
			}
			this.fb = this.fbFb;
		}

		this.wg = new Ext.WindowGroup();
		this.wg.zseed = 9020;
		this.wg.register(this.fb);
		this.wg.bringToFront(this.fb);
		this.fb.show();
		this.fb.setValue(url);
	}
};